package com.turnengine.client.local.turn.bean;

import com.turnengine.client.local.turn.enums.TurnUpdating;
import com.turnengine.client.local.turn.enums.TurnsEnabled;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Turn Summary.
 */
public class TurnSummary implements ITurnSummary, Comparable<ITurnSummary> {

	/** The number. */
	private int number = -1;
	/** The enabled. */
	private TurnsEnabled enabled = TurnsEnabled.DISABLED;
	/** The updating. */
	private TurnUpdating updating = TurnUpdating.NOT_UPDATING;
	/** The time to next turn. */
	private long timeToNextTurn = -1;
	/** The time of next turn. */
	private long timeOfNextTurn = -1;
	/** The current time. */
	private long currentTime = -1;

	/**
	 * Creates a new Turn Summary.
	 */
	public TurnSummary() {
	}

	/**
	 * Creates a new Turn Summary.
	 * @param number the number
	 * @param enabled the enabled
	 * @param updating the updating
	 * @param timeToNextTurn the time to next turn
	 * @param timeOfNextTurn the time of next turn
	 * @param currentTime the current time
	 */
	public TurnSummary(int number, TurnsEnabled enabled, TurnUpdating updating, long timeToNextTurn, long timeOfNextTurn, long currentTime) {
		setNumber(number);
		setEnabled(enabled);
		setUpdating(updating);
		setTimeToNextTurn(timeToNextTurn);
		setTimeOfNextTurn(timeOfNextTurn);
		setCurrentTime(currentTime);
	}

	/**
	 * Creates a new Turn Summary.
	 * @param turnSummary the turn summary
	 */
	public TurnSummary(TurnSummary turnSummary) {
		setNumber(turnSummary.getNumber());
		setEnabled(turnSummary.getEnabled());
		setUpdating(turnSummary.getUpdating());
		setTimeToNextTurn(turnSummary.getTimeToNextTurn());
		setTimeOfNextTurn(turnSummary.getTimeOfNextTurn());
		setCurrentTime(turnSummary.getCurrentTime());
	}

	/**
	 * Creates a new Turn Summary.
	 * @param iTurnSummary the i turn summary
	 */
	public TurnSummary(ITurnSummary iTurnSummary) {
		setNumber(iTurnSummary.getNumber());
		setEnabled(iTurnSummary.getEnabled());
		setUpdating(iTurnSummary.getUpdating());
		setTimeToNextTurn(iTurnSummary.getTimeToNextTurn());
		setTimeOfNextTurn(iTurnSummary.getTimeOfNextTurn());
		setCurrentTime(iTurnSummary.getCurrentTime());
	}

	/**
	 * Returns the number.
	 * @return the number.
	 */
	public int getNumber() {
		return number;
	}

	/**
	 * Returns the enabled.
	 * @return the enabled.
	 */
	public TurnsEnabled getEnabled() {
		return enabled;
	}

	/**
	 * Returns the updating.
	 * @return the updating.
	 */
	public TurnUpdating getUpdating() {
		return updating;
	}

	/**
	 * Returns the time to next turn.
	 * @return the time to next turn.
	 */
	public long getTimeToNextTurn() {
		return timeToNextTurn;
	}

	/**
	 * Returns the time of next turn.
	 * @return the time of next turn.
	 */
	public long getTimeOfNextTurn() {
		return timeOfNextTurn;
	}

	/**
	 * Returns the current time.
	 * @return the current time.
	 */
	public long getCurrentTime() {
		return currentTime;
	}

	/**
	 * Sets the number.
	 * @param number the number to set.
	 */
	public void setNumber(int number) {
		this.number = number;
	}

	/**
	 * Sets the enabled.
	 * @param enabled the enabled to set.
	 */
	public void setEnabled(TurnsEnabled enabled) {
		this.enabled = enabled;
	}

	/**
	 * Sets the updating.
	 * @param updating the updating to set.
	 */
	public void setUpdating(TurnUpdating updating) {
		this.updating = updating;
	}

	/**
	 * Sets the time to next turn.
	 * @param timeToNextTurn the time to next turn to set.
	 */
	public void setTimeToNextTurn(long timeToNextTurn) {
		this.timeToNextTurn = timeToNextTurn;
	}

	/**
	 * Sets the time of next turn.
	 * @param timeOfNextTurn the time of next turn to set.
	 */
	public void setTimeOfNextTurn(long timeOfNextTurn) {
		this.timeOfNextTurn = timeOfNextTurn;
	}

	/**
	 * Sets the current time.
	 * @param currentTime the current time to set.
	 */
	public void setCurrentTime(long currentTime) {
		this.currentTime = currentTime;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1051, 37);
		hash.append(number);
		hash.append(enabled);
		hash.append(updating);
		hash.append(timeToNextTurn);
		hash.append(timeOfNextTurn);
		hash.append(currentTime);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof TurnSummary) {
			TurnSummary compare = (TurnSummary) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.number, compare.number);
			equals.append(this.enabled, compare.enabled);
			equals.append(this.updating, compare.updating);
			equals.append(this.timeToNextTurn, compare.timeToNextTurn);
			equals.append(this.timeOfNextTurn, compare.timeOfNextTurn);
			equals.append(this.currentTime, compare.currentTime);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ITurnSummary compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.number, compare.getNumber());
		builder.append(this.enabled, compare.getEnabled());
		builder.append(this.updating, compare.getUpdating());
		builder.append(this.timeToNextTurn, compare.getTimeToNextTurn());
		builder.append(this.timeOfNextTurn, compare.getTimeOfNextTurn());
		builder.append(this.currentTime, compare.getCurrentTime());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("number", number);
		if (enabled != null) {
			string.append("enabled", enabled);
		}
		if (updating != null) {
			string.append("updating", updating);
		}
		string.append("timeToNextTurn", timeToNextTurn);
		string.append("timeOfNextTurn", timeOfNextTurn);
		string.append("currentTime", currentTime);
		return string.toString();
	}
}
